{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#线程 Thread\n",
    "#group :线程组\n",
    "#target :线程目标函数\n",
    "#*args :线程目标函数的参数 传任意多个参数 以元组形式，一个元素的元组也要加,\n",
    "#*kwargs :线程目标函数的参数 字典\n",
    "#daemon :守护线程\n",
    "#name :线程名\n",
    "#join :等待线程结束\n",
    "#setDaemon :设置守护线程\n",
    "#互斥锁 :锁 \n",
    "#acquire :获取锁\n",
    "#release :释放锁\n",
    "# import threading\n",
    "# import time\n",
    "# def wdata(name):\n",
    "#     print(name,\"在跳舞\")\n",
    "#     time.sleep(1)\n",
    "\n",
    "# if __name__ == \"__main__\":\n",
    "#     for i in range(5):\n",
    "#         t=threading.Thread(target=dance,args=(\"张三\",))\n",
    "#         t.start()\n",
    "#multiprocessing :多进程 import multiprocessing\n",
    "# Process :进程 继承自threading.Thread\n",
    "#target :进程目标函数\n",
    "#start :启动进程\n",
    "#join :等待进程结束\n",
    "#close :关闭进程\n",
    "#is_alive :判断进程是否存活\n",
    "#name :进程名\n",
    "#pid :进程id\n",
    "#queue :进程队列 Queue.Queue()\n",
    "# q=Queue(3) #队列长度为3\n",
    "# q.put(\"a\")#放入队列\n",
    "# q.get()#获取队列\n",
    "# q.empty()#判断队列是否为空\n",
    "# q.full()#判断队列是否为满\n",
    "\n",
    "#greenlet :协程 import greenlet\n",
    "#greenlet :协程 一个线程执行多个任务 线程自动切换\n",
    "# from greenlet import greenlet\n",
    "# def f1():\n",
    "#     print(\"f1\")\n",
    "#     gr2.switch()#切换到gr2\n",
    "#     print(\"f1 again\")\n",
    "# def f2():\n",
    "#     print(\"f2\")\n",
    "#     gr1.switch()#切换到gr1\n",
    "#     print(\"f2 again\")\n",
    "# if __name__ == \"__main__\":\n",
    "#     gr1=greenlet(f1)\n",
    "#     gr2=greenlet(f2)\n",
    "#     gr1.switch()#切换到gr1\n",
    "\"\"\"f1\n",
    "f2\n",
    "f1 again\n",
    "\"\"\"\n",
    "#gevent :协程 import gevent \n",
    "#gevent :协程 一个线程执行多个任务 线程自动切换\n",
    "#gevent.spawn(f1) #创建协程\n",
    "#gevent.joinall([gevent.spawn(f1),gevent.spawn(f2)]) #等待协程结束\n",
    "#gevent.sleep(1) #挂起1秒\n",
    "#gevent.kill(gevent.spawn(f1)) #杀死协程\n",
    "#gevent.join() #等待某个协程结束\n",
    "# from gevent import monkey\n",
    "# monkey.patch_all() #将程序中用到的耗时操作，替换成gevent中自己实现的模块，从而实现协程 自动替换time.sleep()函数\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
